<?php
/**
 * Created by PhpStorm.
 * User: yy
 * Date: 2019/5/15
 * Time: 14:53
 */

namespace app\api\controller;

use app\common\validate\environmentAnalysis\EnvironmentAnalysisPollutantValidate;
use app\common\service\environmentAnalysis\EnvironmentAnalysisPollutantService;

class EnvironmentAnalysisPollutant extends BaseController
{
    /**
     * 获取污染物分析左上侧表格
     * @author yy by 2019/5/15
     */
    public function getTable()
    {
        $param               = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-28 00:00:00', 'end_time' => '2019-06-06 00:00:00', 'region_id' => 53];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'table');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getTable($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 行业贡献企业排放总量占比
     * @author yy by 2019/5/21
     * @throws \MongoDB\Driver\Exception\Exception
     */
    public function getIndustryCompanyEmissionRate()
    {
        $param               = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-12 00:00:00', 'end_time' => '2019-05-15 00:00:00', 'region_id' => 53, 'company_pollutant_name' => 'so2'];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'industryCompanyEmissionRate');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getIndustryCompanyEmissionRate($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 获取行业企业污染物排放量排名
     * @author yy by 2019/5/16
     */
    public function getEmissionRank()
    {
        $param               = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2018-02-01', 'end_time' => '2018-03-01', 'company_pollutant_name' => 'so2', 'region_id' => 53, 'industry_id' => 1];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'emissionRank');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getEmissionRank($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 获取行业企业贡献度排名
     * @author yy by 2019/5/22
     */
    public function getContributionRank()
    {
        $param               = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-06-01 00:00:00', 'end_time' => '2019-06-05 00:00:00', 'contribute_pollutant_name' => 'so2', 'region_id' => 53, 'industry_id' => 1];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'contributionRank');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getContributionRank($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 首要污染物趋势图
     * @author yy by 2019/5/16
     */
    public function getPrimaryPollutantTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-10', 'end_time' => '2019-05-15', 'primary_pollutant_name' => 'so2', 'region_id' => 53, 'station_id' => 0];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'primaryPollutantTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getPrimaryPollutantTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * @author yy by 2019/5/24
     * @author yy by 2019/6/4
     */
    public function getIndustryEmissionTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-01', 'end_time' => '2019-05-05', 'industry_id'=>1,'company_pollutant_name' => 'so2',];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'industryEmissionTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getIndustryEmissionTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 获取行业贡献度趋势图
     * @author yy by 2019/5/23
     */
    public function getIndustryContributeTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-10', 'end_time' => '2019-05-15', 'region_id' => 53, 'station_id' => 1, 'industry_id'=>1, 'contribute_pollutant_name'=>'so2'];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'industryContributeTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getIndustryContributeTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     *  企业排放趋势图及平均值
     * @author yy by 2019/5/16
     */
    public function getCompanyEmissionTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-04-10', 'end_time' => '2019-04-15', 'company_pollutant_name' => 'so2', 'industry_id' => 4, 'company_id' => 36];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'companyEmissionTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getCompanyEmissionTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 企业贡献度趋势图
     * @author yy by 2019/5/24
     */
    public function getCompanyContributeTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-10', 'end_time' => '2019-05-15', 'region_id' => 53, 'station_id' => 1, 'contribute_pollutant_name' => 'so2', 'industry_id' => 6, 'company_id' => 101];
        $validate = new EnvironmentAnalysisPollutantValidate();
        $result   = $validate->check($param, [], 'companyContributeTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisPollutantService = new EnvironmentAnalysisPollutantService();
            $list                                = $environmentAnalysisPollutantService->getCompanyContributeTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

}